home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 4.6 KB | 160 lines | [TEXT/MPS ] |
- ;=============================================================================
- ; Failure Handler Assembly Routines
- ;
- ; KNOWN LIMITATIONS
- ;
- ; Copyright © 1984-1990 Apple Computer, Inc. All rights reserved.
- ;
- ; when who what
- ; -------- ---- --------------------------------------------------------------
- ; 88.07.28 srf add header and includes for Macros
- ; ----------------------------------------------------------------------------
-
- Blanks On
- String AsIs
- Case On
-
- Print Off
- Include 'Macros.a'
-
- LOAD 'ProgStrucMacs.d'
- LOAD 'FlowCtlMacs.d'
- Print On
-
- ;---------------------------------------------------------------------------------------------------
-
- nSavedRegs Equ 12
-
- ; flags to indicate which type of handler is stored in the FailInfo record
- kPascalProcCall Equ 0
- kCFuncCall Equ 1
-
- Seg 'MAFailureRes'
- ;-------------------------------------------------------------------
- ;PROCEDURE CatchFailures(VAR fi: FailInfo; PROCEDURE Handler(e: INTEGER; m: LONGINT)); EXTERNAL;
- ;-------------------------------------------------------------------
- CATCHFAILURES Proc Export
- DATA
- Import gTopHandler:Data
- CODE
-
- A6Link Equ 4 ; static link which the Pascal compiler
- ; automatically pushes on the stack after
- ; pushing a ProcPtr ("PROCEDURE Handler")
- handler Equ A6Link + 4 ; the ProcPtr ("PROCEDURE Handler")
- fiVAR Equ handler + 4
- parmSize Equ fiVAR + 4 - A6Link
-
- Head
- Move.L fiVAR(SP),A0 ; get pointer to FailInfo block
-
- MoveM.L A2-A7/D2-D7,(A0) ; save All regs first
- Add #nSavedRegs*4,A0 ; advance pointer by # bytes regs
-
- Move.W #kPascalProcCall,(A0)+ ; set flags field. 0 is for CatchFailures
-
- Clr.W (A0)+ ; clear error field
- Clr.L (A0)+ ; clear message field
-
- Lea A6Link(SP),A1 ; save the A6Link And Proc ptr
- Move.L (A1)+,(A0)+ ; save the A6Link
- Move.L (A1)+,(A0)+ ; save the Proc ptr
-
- Move.L gTopHandler(A5),(A0)+ ; Link the FailInfo into the LIST
- Move.L fiVAR(SP),gTopHandler(A5)
- If qDebug Then
- Move.L (SP),(A0)+ ; remember the caller's PC
- EndIf
-
- exit
- Move.L (SP)+,A0
- Add.L #parmSize,SP
- Jmp (A0)
- Tail CATCHFAILURES
-
- ;-------------------------------------------------------------------
- ;FUNCTION Try(VAR fi: FailInfo): BOOLEAN; EXTERNAL C;
- ;-------------------------------------------------------------------
- Try Proc Export
- DATA
- Import gTopHandler:Data
- CODE
-
- fiVAR Equ 4
- parmSize Equ fiVAR
-
- Head
- Move.L fiVAR(SP),A0 ; get pointer to FailInfo block
-
- MoveM.L A2-A7/D2-D7,(A0) ; save All regs first
- Add #nSavedRegs*4,A0 ; advance pointer by # bytes regs
-
- Move.W #kCFuncCall,(A0)+ ; set flags field. 1 is for Try
-
- Clr.W (A0)+ ; clear error field
- Clr.L (A0)+ ; clear message field
-
- Clr.L (A0)+ ; clear the A6Link. Not used with Try
- Move.L (SP), (A0)+ ; save the return address as the continuation ptr
-
- Move.L gTopHandler(A5),(A0)+ ; Link the FailInfo into the LIST
- Move.L fiVAR(SP),gTopHandler(A5)
- If qDebug Then
- Move.L (SP),(A0)+ ; remember the caller's PC
- EndIf
-
- exit
- Move.L (SP)+,A0
- ; Add.L #parmSize,SP
- Move.W #1,D0 ; Boolean true, enter the conditioned block of code to try
- Jmp (A0)
- Tail Try
-
-
- Seg 'MAFailureRes'
- ;-------------------------------------------------------------------
- ;PROCEDURE DoFailure(pf: PFailInfo); EXTERNAL;
- ;-------------------------------------------------------------------
- DOFAILURE Proc Export
- Import FAILURE
-
- pf Equ 4
-
- Head
- Move.L pf(SP),A0 ; get pointer to FailInfo
- MoveM.L (A0),A2-A7/D2-D7 ; restore regs (can't use A7 anymore)
- Add #nSavedRegs*4,A0 ; advance pointer
-
- CmpI.W #kPascalProcCall,(A0)+
- Beq.S PascalProcCall
- Clr.W D0 ; Boolean false, enter the conditioned block of failure code
- Move.l 10(A0),A0
- Jmp (A0)
-
- PascalProcCall
- Move.W (A0)+,D0 ; get error
- Move.L (A0)+,D1 ; And message
-
- MoveM.L D0/D1,-(SP) ; save for later use
-
- Move.W D0,-(SP)
- Move.L D1,-(SP) ; parameters to failure handler
-
- Move.L (A0)+,D0 ; check the A6Link
- Beq.S @1 ; If NIL Then don't pass it
- Move.L D0,-(SP) ; Else Do pass it
- @1
- Move.L (A0)+,A0 ; get address of failure handler
-
- Jsr (A0) ; call failure handler
-
- MoveM.L (SP)+,D0/D1 ; get error & message back
- Move.W D0,-(SP)
- Move.L D1,-(SP) ; parameters to Failure
- Jsr FAILURE
-
- ; should Not return
- Tail DOFAILURE
-
- End
-